﻿
/****************************** 
 * 
 *  Create By: Arthur.li
 *  
 *  Create At: 2009年4月24日 10:41:12
 *  
 *  Description: 移动设备管理
 *  
 *  Remark: 
 *  
 * ****************************/


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Jumpton.Persistent;
using Jumpton.SFA.Server.Entity;
using Jumpton.SFA.Server.BusinessRule;


public partial class Mobile_MobileList : PageBase
{
     protected String PostURL;
     // 当前对该设备的操作提示
     String _controlInfo = " -- {0}";
    protected void Page_Load(object sender, EventArgs e)
    {
        PostURL = "MobileModify.ashx?" + Request.QueryString.ToString();
        if (!string.IsNullOrEmpty(Request["id"]))
        {

           

        }

        else if (!IsPostBack)
        {
            DataBind();
            BindData();
        }
    }


    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (txtIMEI.Value.Equals(""))
        {
            ShowMessage(Resources.Mobile.HaveNotCompleteMobileInfo);
            return;
        }

        MobileDeviceInfo mobile = null;

        if (true) // 当前为创建
        {
            // 判断输入的IMEI是否已经存在
            mobile = new MobileDeviceInfoManager().LoadByCode(txtIMEI.Value);

            if (mobile != null) // 已经存在
            {
                ShowMessage(Resources.Mobile.IMEIExists);
                return;
            }

            // 创建一个
            mobile = new MobileDeviceInfo();
        }
        else
        {
            // 获得当前修改的移动设备信息
            //mobile = new MobileDeviceInfoManager().LoadByCode(txtSelect.Value);
        }

        mobile.IMEICode = txtIMEI.Value;
        //mobile.ACTIVE = rbtnIsActive.Items[0].Selected;
        //mobile.Model = txtModel.Value;
        mobile.BrandName = txtBrand.Value;
        mobile.LASTUP_DATER = MyStateManager.Name;
        mobile.Save();

        if (mobile.ID > 0)
        {
            // 提示修改成功
            ShowMessage(Resources.Mobile.ModifyDeviceSuccess);
        }
        else
        {
            // 提示创建成功
            ShowMessage(Resources.Mobile.CreateDeviceSuccess);
        }

        // 没有选择"继续创建", 或者当前为修改操作
        //if (!chkMore.Visible || !chkMore.Checked || !txtSelect.Value.Equals(""))
        //{
        //    chkMore.Visible = false;
        //    PreCreate(false);
        //    litInfo.Text = "";
        //}
        //Reset();
        BindData();
    }

 

    /// <summary>
    /// 向设备列表中绑定数据
    /// </summary>
    protected void BindData()
    {
        ObjectTable table = new MobileDeviceInfoManager().QuickSearch(txtSearch.Value);
        GridView1.PreRender += new EventHandler(GridView1_PreRender);
        GridView1.SelectedIndexChanged+=new EventHandler(GridView1_SelectedIndexChanged);
        GridView1.DataSource = table;
        GridView1.DataBind();

    }

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        // 提示正在修改
        litInfo.Text = String.Format(_controlInfo, Resources.SiteMap.ModifyText);

        MobileDeviceInfo deviceInfo = new MobileDeviceInfoManager().LoadByCode(GridView1.SelectedValue.ToString());

        if (deviceInfo == null)
        {
            return;
        }

        // 隐藏控件记录Mobile的IMEI信息
        //txtSelect.Value = deviceInfo.IMEICode;
        txtBrand.Value = deviceInfo.BrandName;
        txtIMEI.Value = deviceInfo.IMEICode;
        //txtModel.Value = deviceInfo.Model;
        //txtUpdateBy.Value = deviceInfo.LASTUP_DATER;
       // txtUpdateTime.Value = deviceInfo.LAST_UPDATE_TIME.ToString();
       // rbtnIsActive.Items[0].Selected = deviceInfo.ACTIVE;
       // chkMore.Visible = false;
       // PreCreate(true);
    }
  


    void GridView1_PreRender(object sender, EventArgs e)
    {
        if (this.GridView1.Rows.Count > 0)
        {
            //设置thead下的td替换成th


            //加入<thead>与<tbody>
            this.GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;
            //加入<tfoot>
            this.GridView1.FooterRow.TableSection = TableRowSection.TableFooter;
        }

    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        BindData();
    }

   
}